import jsonpath

d={
    "error_code": 0,
    "stu_info":
    [
        {"id": 223,
         "name": "安妮",
         "sex": "女",
         "classname": "212期",
         "data": {
             "name": "测试1",
             "data": {
                 "name": "测试2"
             }
         }
         },
        {"id": 224,
         "name": "景龙",
         "sex": "男",
         "classname": "212期"
         },
        {"id": 225,
         "name": "MS226",
         "classname": "212期"
         }
    ]
}

# name = d["stu_info"][0]["name"]
# print(name)

# # 模糊匹配  匹配所有学员name
# names_list = jsonpath.jsonpath(d, "$..name")
# print(names_list)

# # 获取安妮的值  匹配第一个学员name
# name_anni = jsonpath.jsonpath(d, "$.stu_info[0].name")
# print(name_anni)

# #  匹配第一个学员下面所有的name
# names = jsonpath.jsonpath(d, "$.stu_info[0]..name")
# print(names)

# #匹配前两个学员的信息
# infos = jsonpath.jsonpath(d, "$.stu_info[:2]")
# print(infos)

# # 取性别为女的学员的信息
# data_info = jsonpath.jsonpath(d, "$.stu_info[?(@.sex=='女')].name")
# print(data_info)

# print(jsonpath.jsonpath(d, "$.stu_info[?(@.sex)]"))